/*
 * Description: Contains functions for bootloader logic.
 *
 * Created: 07-03-2013 16:08:36
 *  Author: Bootie
 */ 


#ifndef BOOTLOADER_H_
#define BOOTLOADER_H_
#include <avr/io.h>
#include <avr/boot.h>
#include <avr/pgmspace.h>
#include "../Headers/Filehandler.h"
#include "../Headers/Filesystemhandler.h"

// Page size(Bytes)
#define	PAGESIZE 128

// Application start location
#define	APP_START	0x0000

// Settings
// :Filename
#define HEX_FILENAME "/ATMF.txt"

// :Debugging
#define DEBUG_BOOTLOADER

/************************************************************************/
/* The class                                                            */
/************************************************************************/
class Bootloader
{
    // Members
    private:
    Filehandler *_fileHandler;
    Filesystemhandler *_fileSystem;
    unsigned int _writeAddress;
    
    // Functions
    private:
    Bootloader();
    public:
    ~Bootloader();
    static Bootloader& GetInstance(); // Singleton
    
    // :Util
    public:
    /*
        Description: Checks for program available.
    */
    bool ProgramAvailable();

    /*
        Description: Runs program loaded on chip.
        Note: Does not return.
    */
    void RunProgram();

    /*
        Description: Loads program onto chip.
        Note: Deletes any old code.
    */
    bool LoadProgram();
    
    // :Helper functions
    private:
    void Init();
};
#endif /* BOOTLOADER_H_ */